package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.sc.nft.entity.UserBusinessCard;
import com.sc.nft.mapper.UserBusinessCardMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class UserBusinessCardDao extends ServiceImpl<UserBusinessCardMapper, UserBusinessCard> {


    public UserBusinessCard getByUserId(Long userId) {
        LambdaQueryWrapper<UserBusinessCard> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserBusinessCard::getUserId,userId);
        wrapper.orderByDesc(UserBusinessCard::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Boolean judgeUserIsActivationBusinessCard(Long userId) {
        LambdaQueryWrapper<UserBusinessCard> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserBusinessCard::getUserId,userId);
        return SqlHelper.retBool(count(wrapper));

    }
    
}
